<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<jsp:directive.include file="seguranca/controleDeAcesso.jsp" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Minha Biblioteca</title>
<style>
ul li{
display:inline;
}
</style>

</head>
<body>

	<f:view>
		<h2>
			Biblioteca de
			<h:outputText value="#{usuarioMB.usuario.nome}"></h:outputText>
		</h2>
		<h:form>
			<nav id="menu">
			<ul>
				<li>
					<h:commandLink action="listaUsuarios.jsp">
						<h:outputText value="Listar usuários"></h:outputText>
					</h:commandLink>
				</li>
				<li>
					<h:commandLink action="listarLivros.jsp">
						<h:outputText value="Listar Livros"></h:outputText>
					</h:commandLink>
				</li>
				
				
				<li>
					<h:commandLink action="Cadastrolivro.jsp">
						<h:outputText value="Cadastrar Livros"></h:outputText>
					</h:commandLink>
				</li>
				<li>
						<h:commandLink action="#{usuarioMB.logout}" >
						<h:outputText value="Efetuar Logout"></h:outputText>
						</h:commandLink>
				</li>
			</ul>
			</nav>
			
			
		</h:form>
		
		<h:form id="cadastroemprestimo">
			Usuário cadastrado no sistema <input type="checkbox" id="cadastrado" value="true">
			
			<p>Responsável: 
				<h:selectOneMenu style="display:none;" id="users" value="#{cadastraemprmb.novoemprestimo.id_responsavel }">
	    			 	
	    			<f:selectItems value="#{usuarioMB.usuarioscadastrados}" var="user" itemValue="#{user.id}" itemLabel="#{user.nome}" />
				</h:selectOneMenu>
				
				<h:inputText id="nome_usuario" value="#{cadastraemprmb.novoemprestimo.nome_responsavel}"></h:inputText>
			</p>
			<p>Telefone: <h:inputText value="#{cadastraemprmb.novoemprestimo.telefone_responsavel }"></h:inputText> </p>
			<p>Email: <h:inputText value="#{cadastraemprmb.novoemprestimo.email_responsavel }"></h:inputText> </p>
			
			<h:commandButton value="Emprestar" action="#{cadastraemprmb.emprestimoLivro}"></h:commandButton>
		</h:form>
		
	</f:view>
	<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
	<script>
	 	$('#cadastrado').change(function() {
        if($(this).is(":checked")) {
           $('#cadastroemprestimo\\:users').show();
           $('#cadastroemprestimo\\:nome_usuario').hide();
            $('#cadastroemprestimo\\:nome_usuario').val(null);
        }else{
           $('#cadastroemprestimo\\:users').hide();
           $('#cadastroemprestimo\\:nome_usuario').show();
        }
               
    });
	
	</script>
</body>
</html>